#!/usr/bin/env python
#coding:utf-8

import wx

class DomainTree(wx.TreeCtrl):
    def __init__(self, parent, mainframe):
        wx.TreeCtrl.__init__(self, parent, style = wx.TR_DEFAULT_STYLE | wx.TR_EXTENDED)
        self.mainframe = mainframe
        
        isz = (16,16)
        il = wx.ImageList(isz[0], isz[1])
        il.Add(wx.Bitmap('images/module.png'))
        il.Add(wx.Bitmap('images/method.gif'))
        il.Add(wx.Bitmap('images/plus.png'))
        
        self.AssignImageList(il)
        
        self.root = self.AddRoot(u'功能导航', 0)
        
        self.conroot = self.AppendItem(self.root, u'四轮定位', 2)
        
        self.conview = self.AppendItem(self.conroot, u'图形视图', 1)
        self.resultview = self.AppendItem(self.conroot, u'结果视图', 1)
        
        self.manualroot = self.AppendItem(self.root, u'手动控制', 2)
        self.manualview = self.AppendItem(self.manualroot, u'手动操作', 1)
        
        self.spcview = self.AppendItem(self.root, u'SPC分析', 2)
        
        self.lcambangleview = self.AppendItem(self.spcview, u'左外倾偏差', 1)
        self.lconsangleview = self.AppendItem(self.spcview, u'左前束偏差', 1)
        self.rcambangleview = self.AppendItem(self.spcview, u'右外倾偏差', 1)
        self.rconsangleview = self.AppendItem(self.spcview, u'右前束偏差', 1)
        
        self.ExpandAll()
        
        self.SelectItem(self.root)
        
        self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
        
        self.CreateDomainView(self.conview)
        self.CreateDomainView(self.resultview)
        
    def OnTreeSelChanged(self, evt):
        self.CreateDomainView(evt.GetItem())
        
    def OnLeftDClick(self, evt):
        pt = evt.GetPosition()
        item, flags = self.HitTest(pt)
        self.mainframe.Freeze()
        self.CreateDomainView(item)
        self.mainframe.Thaw()
        
    def CreateDomainView(self, item):
        if self.conview == item:
            self.mainframe.CreateMainView()
        elif self.resultview == item:
            self.mainframe.CreateResultView()
        elif self.manualview == item:
            self.mainframe.CreateManualView()
        elif self.lcambangleview == item:
            self.mainframe.CreateLCambAngleSpcView()
        elif self.lconsangleview == item:
            self.mainframe.CreateLConsAngleSpcView()
        elif self.rcambangleview == item:
            self.mainframe.CreateRCambAngleSpcView()
        elif self.rconsangleview == item:
            self.mainframe.CreateRConsAngleSpcView()
        
class DomainPanel(wx.Panel):
    def __init__(self, parent, mainframe):
        wx.Panel.__init__(self, parent)
        self.mainframe = mainframe
        
        sizer1 = wx.BoxSizer(wx.VERTICAL)
        
        self.tree = DomainTree(self, self.mainframe)
        sizer1.Add(self.tree, 1, wx.ALL | wx.EXPAND, 2)
        
        self.SetSizer(sizer1)